﻿using System;
using System.Collections.Generic;

using System.Text;
using ITAP.ShprossesBuilder.Modelling.Components;

namespace ITAP.ShprossesBuilder.Manipulation
{
    public class CommandPropertyGridValueChanged : SerializedUndoRedo, ICommand
    {
        private bool isNeedUpdate = false;
        //private ModelContainer oldModelContainer;
        //private ModelContainer redoModelContainer;

        //private ModelControl modelControl;

        public CommandPropertyGridValueChanged(ModelControl modelControl)
        {
            this.modelControl = modelControl;
        }

        #region ICommand Members

        public void StartExecute()
        {
            isNeedUpdate = false;
            undoModelContainer = (ModelContainer)modelControl.ModelContainer.Clone();
        }

        public void Execute()
        {
        }

        public void EndExecute()
        {
            isNeedUpdate = true;
        }

        //public bool CanUndo
        //{
        //    get { return true; }
        //}

        //public bool Undo()
        //{
        //    redoModelContainer = modelControl.ModelContainer;
        //    modelControl.ModelContainer = oldModelContainer;
        //    return true;
        //    //throw new NotImplementedException();
        //}

        //public bool Redo()
        //{
        //    throw new NotImplementedException();
        //}

        public string Name
        {
            get { return "Изменение параметра через панель свойств"; }
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            CommandPropertyGridValueChanged clone = new CommandPropertyGridValueChanged(modelControl);
            //clone.MouseEvent = this.MouseEvent;
            //clone.MouseDownPoint = this.MouseDownPoint;
            //clone.MouseMovePoint = this.MouseMovePoint;
            //clone.MouseUpPoint = this.MouseUpPoint;
            //clone.ComponentsForProcessing = new List<IComponent>(this.ComponentsForProcessing);
            //clone.CanUndo = this.CanUndo;

            if (this.undoModelContainer != null)
                clone.undoModelContainer = (ModelContainer)this.undoModelContainer.Clone();
            if (this.redoModelContainer != null)
                clone.redoModelContainer = (ModelContainer)this.redoModelContainer.Clone();

            return clone;
        }

        #endregion

        #region ICommand Members


        public bool IsNeedModelUpdate
        {
            get { return isNeedUpdate; }
        }

        #endregion

        public override string ToString()
        {
            return this.Name;
        }

        #region ICommand Members

        private bool enabled = true;
        public bool Enabled
        {
            get
            {
                return enabled;
            }
            set
            {
                enabled = value;
            }
        }

        #endregion

        #region ICommand Members


        public bool IsNeedVisitorsUpdate
        {
            get { return true; }
        }

        #endregion
    }
}
